
import { DefaultLayout, GraphNode } from "@/js/components/GraphNode"
import { GraphView } from "@/js/components/GraphView"
import { InputLinkNodeAny, InputLinkNodeBoolean, InputLinkNodeDynamics } from "@/js/components/InputLinkNode"

export class Or extends GraphNode{
    layout?: DefaultLayout
    static menuName = "或 ||"
    name = "或 ||"
    
    load(){
        super.load()

        const layout = new this.DefaultLayout(this, this.graphView as GraphView, false, false)
        this.layout = layout
        this.appendChild(layout.container)

        layout.main?.left.appendChild(new InputLinkNodeDynamics(this, this.graphView as GraphView, {
            name: "value1",
            desc: '值',
            placeholder: "",
            showInput: false,
            model: "entry",
        }))

        layout.main?.left.appendChild(new InputLinkNodeDynamics(this, this.graphView as GraphView, {
            name: "value2",
            desc: '值',
            showInput: false,
            model: "entry",
        }))

        layout.main?.right.appendChild(new InputLinkNodeBoolean(this, this.graphView as GraphView, {
            name: "value3",
            desc: '值',
            showInput: false,
            model: "output",
            linkMaxCount: 1000
        }))
    }
}

Or.parser =  ({node,next, data})=>{
    data.value1 = data.value1 || next(node.enters.value1) || node.userData.enters.value1 || false
    data.value2 = data.value2 || next(node.enters.value2) || node.userData.enters.value2 || false

    return `(${data.value1}||${data.value2})`
}
